﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using APIService.Common;
using System.Web.Mvc;

namespace APIService.Common
{
     [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class PermissionAttribute : System.Web.Mvc.AuthorizeAttribute
    {
         private PermissionCustomMode CustomMode;
         public PermissionAttribute(PermissionCustomMode mode)
         {
             CustomMode = mode;
         }

         public override void OnAuthorization(AuthorizationContext filterContext)
         {
             //权限拦截是否忽略
             if (CustomMode == PermissionCustomMode.Ignore)
             {
                 return;
             }
         }

         protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
         {
             //if (filterContext.HttpContext.User.Identity.IsAuthenticated)
             //{
             //	base.HandleUnauthorizedRequest();
             //}
             //else
             //{
             //	filterContext.Result = new RedirectToRouteResult(new
             //	RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
             //}
         }
    }
}